package com.midea.ai.air.ui.home.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.midea.ai.air.R;
import com.midea.ai.air.ui.home.data.SelectRoomModel;

import java.util.List;

/**
 * Created by ouyangdi on 2016/4/25.
 * 添加家电->选择房间Adapter
 */
public class SelectRoomAdapter extends ArrayAdapter<SelectRoomModel>{
    private LayoutInflater mInflater;

    public SelectRoomAdapter(Context context, int resource, List<SelectRoomModel> objects) {
        super(context, resource, objects);
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        SelectRoomModel item = getItem(position);
        if(convertView == null) {
            convertView = mInflater.inflate(R.layout.list_item_more, parent, false);
            viewHolder = new ViewHolder();
            viewHolder.tvRoomName = (TextView) convertView.findViewById(R.id.txtView_name);
            viewHolder.ivSelected = (ImageView)convertView.findViewById(R.id.imgView_arrow);
            viewHolder.ivSelected.setImageResource(R.drawable.air_edit_room_device_manager_select);
            viewHolder.botLine = convertView.findViewById(R.id.bottom_line);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder)convertView.getTag();
        }
        viewHolder.tvRoomName.setText(item.getStrRoomName());
        if(item.isSelected()) {
            viewHolder.ivSelected.setVisibility(View.VISIBLE);
        } else {
            viewHolder.ivSelected.setVisibility(View.GONE);
        }

        if(position != getCount()-1) {
            viewHolder.botLine.setVisibility(View.VISIBLE);
        } else {
            viewHolder.botLine.setVisibility(View.INVISIBLE);
        }
        return convertView;
    }

    class ViewHolder {
        public TextView tvRoomName;
        public ImageView ivSelected;
        public View botLine;
    }
}
